import 'dart:async';

import 'package:auto_route/auto_route.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tender_flutter/constant/api_path.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/dialog/share_bottom_sheet.dart';
import 'package:tender_flutter/page/common/helper/data_manager.dart';
import 'package:tender_flutter/page/home/api/api_home.dart';
import 'package:tender_flutter/page/home/model/city_entity.dart';
import 'package:tender_flutter/page/home/model/common_tag_model.dart';
import 'package:tender_flutter/page/home/model/notice_entity.dart';
import 'package:tender_flutter/page/home/supplier_list_home_page.dart';
import 'package:tender_flutter/page/home/tender_list_page.dart';
import 'package:tender_flutter/providers/user_profile.dart';
import 'package:tender_flutter/router/router.dart';
import 'package:tender_flutter/router/router_map.gr.dart';
import 'package:tender_flutter/utils/amap_location.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/share.dart';
import 'package:tender_flutter/widgets/FloatButton.dart';
import 'package:tender_flutter/widgets/base_appbar.dart';
import 'package:tender_flutter/widgets/number_anim_text.dart';
import 'package:tender_flutter/widgets/part_refresh_widget.dart';
import 'package:tender_flutter/widgets/round_tab_indicator.dart';
import 'package:tender_flutter/widgets/sticky_tabbar_delegate.dart';

import 'model/tender_num_entity.dart';

class TabHomePage extends StatefulWidget {
  @override
  _TabHomePageState createState() => _TabHomePageState();
}

class _TabHomePageState extends State<TabHomePage>
    with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  /// 滑动控制器
  TabController _tabController;

  /// tabMenu分类数据
  List<String> _classType;

  /// 热搜关键词
  List<CommonTagModel> _hotKeywords = [];

  /// 公告
  List<NoticeEntity> _noticeDatas = [];

  /// 标讯信息更新数量
  TenderNumEntity _tenderNumEntity;

  /// 当前定位或选择的城市信息
  CityEntity _curCityEntity;

  GlobalKey<PartRefreshWidgetState> _tenderNumGlobalKey = GlobalKey();

  GlobalKey<PartRefreshWidgetState> _hotGlobalKey = GlobalKey();

  GlobalKey<PartRefreshWidgetState> _cityGlobalKey = GlobalKey();

  GlobalKey<PartRefreshWidgetState> _noticeGlobalKey = GlobalKey();

  GlobalKey<PartRefreshWidgetState> _menuIndicatorGlobalKey = GlobalKey();

  List<GlobalKey> _listKey = [
    GlobalKey<TenderListPageState>(),
    GlobalKey<TenderListPageState>(),
    GlobalKey<SupplierListHomePageState>()
  ];

  /// 模块菜单指示器偏位置
  double _alignmentY = -1;

  /// 是否关闭顶部标讯数量显示
  bool _tenderNumOffstage = true;

  /// 获取热门搜索关键词
  Future _getHotKeywords() async {
    var response = await ApiHome.getHotKeywords<List<CommonTagModel>>();
    _hotKeywords = response.result;
    _hotGlobalKey.currentState.update();
  }

  /// 每天更新的标讯总量
  Future _getTenerNum() async {
    var response = await ApiHome.getTenderNum<TenderNumEntity>();
    _tenderNumEntity = response.result;
    _tenderNumOffstage = false;
    _tenderNumGlobalKey.currentState.update();
    // 开启倒计时，3s后消失
    Future.delayed(Duration(milliseconds: 5000), () async {
      _tenderNumOffstage = true;
      _tenderNumGlobalKey.currentState.update();
    });
  }

  /// 获取公告
  Future _getAnnouncements() async {
    var response = await ApiHome.getAnnouncement<List<NoticeEntity>>();
    _noticeDatas = response.result;
    _noticeGlobalKey.currentState.update();
  }

  /// 定位城市
  Future _locationCity() async {
    AMapLocationUtils.startLocation((location, refresh) {
      if (location != null) {
        _curCityEntity = location;
        _cityGlobalKey.currentState.update();
        if (refresh) {
          updateListData();
        }
      }
    });
  }

  /// 刷新列表数据
  void updateListData() {
    for (int i = 0; i < _listKey.length; i++) {
      dynamic listPageState = _listKey[i].currentState;
      listPageState.updateData(i == _tabController.index ? true : false);
    }
  }

  /// 菜单模块滑动监听处理
  bool _handleModuleMenuScrollNotification(ScrollNotification notification) {
    final ScrollMetrics metrics = notification.metrics;
    _alignmentY = -1 + (metrics.pixels / metrics.maxScrollExtent) * 2;
    _menuIndicatorGlobalKey.currentState.update();
    return true;
  }

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    _classType = ['招标公告', '中标公告', '供应商'];
    _tabController = TabController(length: _classType.length, vsync: this);

    _tabController.addListener(() {
      dynamic listPageState = _listKey[_tabController.index].currentState;
      if (listPageState.isNeedRefreshData ?? false) {
        listPageState.updateData(true);
      }
    });

    /// 页面渲染完成之后的回调，只执行一次
    WidgetsBinding.instance.addPostFrameCallback((mag) async {
      _getHotKeywords();
      _getAnnouncements();
      _getTenerNum();

      /// 为了解决程序第二次进去无法定位问题
      Future.delayed(Duration(milliseconds: 1000), () {
        _locationCity();
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: _topAppBar(),
      body: Column(
          children: [_initTenderNumLayout(), Expanded(child: _bodyContent())]),
    );
  }

  /// 顶部导航栏
  Widget _topAppBar() {
    return BaseAppBar(
      context,
      Consumer(builder:
          (BuildContext ctx, UserProfileInfo profileInfo, Widget child) {
        return IntrinsicHeight(
          child: Stack(
            alignment: Alignment.center,
            children: <Widget>[
              Positioned(
                left: 5,
                child: InkResponse(
                    onTap: () {
                      LRouter.navigatorCtx(context)
                          .push(Routes.cityPage)
                          .then((value) {
                        if (value != null) {
                          CityEntity city = value;
                          _curCityEntity = city;
                          _cityGlobalKey.currentState.update();
                          updateListData();
                        }
                      });
                    },
                    highlightColor: ThemeColors.colorTransparent,
                    child: Padding(
                      padding: EdgeInsets.only(left: ScreenAdapter.width(30)),
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          PartRefreshWidget(_cityGlobalKey, () {
                            return Text(
                              _curCityEntity != null
                                  ? _curCityEntity.title
                                  : "定位中",
                              style: TextStyle(
                                  color: ThemeColors.colorType1,
                                  fontSize: ScreenAdapter.sp(30)),
                            );
                          }),
                          SizedBox(width: ScreenAdapter.width(5)),
                          Image.asset(
                              RPath.imgPath + "icon_black_arrow_down.png",
                              width: ScreenAdapter.width(16))
                        ],
                      ),
                    )),
              ),
              Positioned(
                  child: Container(
                      alignment: Alignment.center,
                      height: ScreenAdapter.height(50),
                      child: Image.asset(RPath.imgPath + "img_home_logo.png",
                          fit: BoxFit.contain))),
              Positioned(
                right: 5,
                child: Offstage(offstage: DataManager.instance.isAppstore ? true : false, child:  InkWell(
                  onTap: () {
                    if (profileInfo.userInfo.isVip()) {
                      LRouter.navigatorCtx(context).push(Routes.inviatePage);
                    } else {
                      LRouter.navigatorCtx(context)
                          .push(Routes.memberCentrePage);
                    }
                  },
                  child: Padding(
                    padding: EdgeInsets.only(right: ScreenAdapter.width(30)),
                    child: Image.asset(
                        RPath.imgPath +
                            (profileInfo.userInfo.isVip()
                                ? "icon_share_orange.png"
                                : "icon_open_vip.png"),
                        width: ScreenAdapter.width(63)),
                  ),
                )),
              ),
            ],
          ),
        );
      }),
      isShowLeading: false,
      titleSpacing: 0,
      elevation: 0,
    );
  }

  /// 内容
  Widget _bodyContent() {
    return Consumer(
        builder: (BuildContext ctx, UserProfileInfo profileInfo, Widget child) {
      return Stack(children: [
        NestedScrollView(
          headerSliverBuilder: (context, innerScrolled) => <Widget>[
            SliverOverlapAbsorber(
              // 传入 handle 值，直接通过 `sliverOverlapAbsorberHandleFor` 获取即可
              handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
              sliver: SliverAppBar(
                elevation: 0,
                backgroundColor: ThemeColors.colorWhite,
                // automaticallyImplyLeading: true,
                forceElevated: innerScrolled,
                expandedHeight: ScreenAdapter.height(
                    (profileInfo.userInfo.isVip()) ? 555 : 435),
                // bottom: PreferredSize(
                //     child: Container(),
                //     preferredSize: Size.fromHeight(ScreenAdapter.height(595))),
                flexibleSpace: FlexibleSpaceBar(
                  collapseMode: CollapseMode.pin,
                  background: Column(
                    children: profileInfo.userInfo.isVip()
                        ? [
                            _initSearchLayout(),
                            _initModuleMenu(),
                            _initModuleZone(),
                            _initNotice(),
                            _initLine()
                          ]
                        : [
                            _initSearchLayout(),
                            _initModuleMenu(),
                            _initNotice(),
                            _initLine()
                          ],
                  ),
                ),
              ),
            ),
            SliverPersistentHeader(
              pinned: true,
              delegate: StickyTabBarDelegate(
                minHeight: 45,
                maxHeight: 45,
                child: _initTabBar(),
              ),
            ),
          ],
          body: TabBarView(
            controller: _tabController,
            children: <Widget>[
              TenderListPage(
                  key: _listKey[0], tenderType: AppConstant.TENDERTYPE_TENDER),
              TenderListPage(
                  key: _listKey[1],
                  tenderType: AppConstant.TENDERTYPE_WINBIDBING),
              SupplierListHomePage(
                  key: _listKey[2], supplietType: AppConstant.SUPPLIER_ALL)
            ],
          ),
        ),
        FloatButton(
          child: GestureDetector(
            onTap: () {
              LRouter.navigatorCtx(context).push(Routes.customerServicePage);
            },
            child: Image.asset(
              RPath.imgPath + "icon_customer_service.png",
              width: ScreenAdapter.width(100),
              height: ScreenAdapter.height(100),
            ),
          ),
          offset: Offset(ScreenAdapter.screenWidth() - ScreenAdapter.width(100),
              ScreenAdapter.screenHeight() - ScreenAdapter.width(100) - 200),
        ),
      ]);
    });
  }

  /// 初始化tabBar
  Widget _initTabBar() {
    return Container(
        // margin: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(20)),
        decoration: BoxDecoration(
          color: ThemeColors.colorWhite,
          // borderRadius:
          //     BorderRadius.all(Radius.circular(ScreenAdapter.width(50)))
        ),
        child: TabBar(
          indicatorPadding: EdgeInsets.zero,
          labelPadding: EdgeInsets.only(bottom: 5),
          onTap: ((index) {}),
          indicator: RoundUnderlineTabIndicator(
              borderSide: BorderSide(
            width: 5,
            color: ThemeColors.colorType6,
          )),
          // indicator: CircleTabIndicator(),
          labelStyle: TextStyle(
            fontSize: ScreenAdapter.sp(33),
            fontWeight: FontWeight.w600,
          ),
          unselectedLabelStyle: TextStyle(
            fontSize: ScreenAdapter.sp(33),
            fontWeight: FontWeight.w600,
          ),
          labelColor: ThemeColors.colorType1,
          unselectedLabelColor: ThemeColors.colorType7,
          tabs: _classType
              .map((e) => Container(
                    alignment: Alignment.center,
                    width: double.infinity,
                    // color: ThemeColors.colorTheme,
                    child: Text(e),
                    padding: const EdgeInsets.only(
                      bottom: 0,
                    ),
                  ))
              .toList(),
          controller: _tabController,
        ));
  }

  /// 初始化标讯数量
  Widget _initTenderNumLayout() {
    return PartRefreshWidget(_tenderNumGlobalKey, () {
      return Offstage(
          offstage: _tenderNumOffstage,
          child: Container(
              width: ScreenAdapter.screenWidth(),
              height: ScreenAdapter.height(70),
              padding:
                  EdgeInsets.symmetric(horizontal: ScreenAdapter.width(30)),
              color: ThemeColors.colorType9,
              child: Stack(children: [
                Align(
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                      Text("今日新增商机 ",
                          style: TextStyle(
                              fontSize: ScreenAdapter.sp(26),
                              color: ThemeColors.colorType7,
                              fontWeight: FontWeight.bold)),
                      _tenderNumEntity == null
                          ? Container()
                          : NumberAnimText(
                              number: _tenderNumEntity != null
                                  ? _tenderNumEntity.num
                                  : 0,
                              duration: 3500,
                              fontColor: ThemeColors.colorType53,
                              fontSize: ScreenAdapter.sp(34),
                            ),
                      Text("条 ",
                          style: TextStyle(
                              fontSize: ScreenAdapter.sp(26),
                              color: ThemeColors.colorType7,
                              fontWeight: FontWeight.bold))
                    ])),
                Align(
                  alignment: Alignment.centerRight,
                  child: GestureDetector(
                      onTap: () {
                        _tenderNumOffstage = true;
                        _tenderNumGlobalKey.currentState.update();
                      },
                      child: Container(
                          width: ScreenAdapter.height(50),
                          height: ScreenAdapter.width(50),
                          child: Image.asset(
                            RPath.imgPath + "icon_close_x.png",
                            width: ScreenAdapter.width(25),
                            height: ScreenAdapter.width(25),
                          ))),
                )
              ])));
    });
  }

  /// 初始化搜索以及热搜关键词
  Widget _initSearchLayout() {
    return Container(
      margin: EdgeInsets.only(
          left: ScreenAdapter.width(30),
          right: ScreenAdapter.width(30),
          top: ScreenAdapter.height(10)),
      child: Column(
        children: <Widget>[
          GestureDetector(
              onTap: () {
                LRouter.navigatorCtx(context).push(Routes.searchListPage,
                    arguments: SearchListPageArguments(
                      isShowCity: true,
                    ));
              },
              child: Container(
                width: double.infinity,
                height: ScreenAdapter.height(65),
                decoration: BoxDecoration(
                  color: ThemeColors.colorType5,
                  borderRadius: BorderRadius.all(
                      Radius.circular(ScreenAdapter.width(14))),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Image.asset(RPath.imgPath + "icon_gray_search.png",
                        width: ScreenAdapter.width(30)),
                    SizedBox(width: ScreenAdapter.width(18)),
                    Text(
                      "请输入招标关键词进行搜索",
                      style: TextStyle(
                          color: ThemeColors.colorType3,
                          fontSize: ScreenAdapter.sp(30)),
                    )
                  ],
                ),
              )),
          Container(
              height: ScreenAdapter.height(80),
              child: IntrinsicHeight(
                child: Row(
                  children: <Widget>[
                    Container(
                      width: ScreenAdapter.width(80),
                      height: ScreenAdapter.height(37),
                      margin: EdgeInsets.only(right: ScreenAdapter.width(20)),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: ThemeColors.colorType9,
                          borderRadius: BorderRadius.all(
                              Radius.circular(ScreenAdapter.width(10)))),
                      child: Text(
                        "热搜",
                        style: TextStyle(
                            fontSize: ScreenAdapter.sp(27),
                            fontWeight: FontWeight.bold,
                            color: ThemeColors.colorType10),
                      ),
                    ),
                    Expanded(
                      child: PartRefreshWidget(_hotGlobalKey, () {
                        return SingleChildScrollView(
                          physics: const BouncingScrollPhysics(),
                          scrollDirection: Axis.horizontal,
                          child: Wrap(
                            direction: Axis.horizontal,
                            children: _hotKeywords
                                .map((item) => ButtonItem(
                                      text: item.title,
                                      callback: () {
                                        LRouter.navigatorCtx(context).push(
                                            Routes.searchListPage,
                                            arguments: SearchListPageArguments(
                                              keyword: item.title,
                                              isShowCity: true,
                                              exactQuery: true,
                                            ));
                                      },
                                    ))
                                .toList(),
                            spacing: ScreenAdapter.width(15),
                            alignment: WrapAlignment.start,
                          ),
                        );
                      }),
                    ),
                  ],
                ),
              )),
        ],
      ),
    );
  }

  /// 初始化模块菜单
  Widget _initModuleMenu() {
    return Container(
      height: ScreenAdapter.height(170),
      margin: EdgeInsets.only(
          left: ScreenAdapter.width(30),
          right: ScreenAdapter.width(30),
          top: ScreenAdapter.height(5)),
      child: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
        Expanded(
            child: NotificationListener<ScrollNotification>(
          onNotification: _handleModuleMenuScrollNotification,
          child: ListView(
              physics: const BouncingScrollPhysics(),
              scrollDirection: Axis.horizontal,
              children: <Widget>[
                ModuleMenuItem(
                  text: "招标查询",
                  image: "img_tender_search.png",
                  callback: () {
                    LRouter.navigatorCtx(context).push(Routes.tenderSearchPage);
                  },
                ),
                ModuleMenuItem(
                  text: "中标查询",
                  image: "img_win_bid_search.png",
                  callback: () {
                    LRouter.navigatorCtx(context).push(Routes.winBidSearchPage);
                  },
                ),
                ModuleMenuItem(
                  text: "企业查询",
                  image: "img_compnay_search.png",
                  callback: () {
                    LRouter.navigatorCtx(context)
                        .push(Routes.companySearchPage);
                  },
                ),
                ModuleMenuItem(
                  text: "失信查询",
                  image: "icon_shixin.png",
                  callback: () {
                    LRouter.navigatorCtx(context).push(Routes.creditSearchPage);
                    // debugPrint("点击回调item");
                  },
                ),
                ModuleMenuItem(
                  text: "供需市场",
                  image: "img_demand_search.png",
                  callback: () {
                    LRouter.navigatorCtx(context).push(Routes.marketSearchPage);
                  },
                ),
                // ModuleMenuItem(
                //   text: "VIP项目",
                //   image: "img_vip_project.png",
                //   callback: () {
                //     debugPrint("点击回调item");
                //   },
                // ),
                ModuleMenuItem(
                  text: "PPP项目",
                  image: "img_ppp_project.png",
                  callback: () {
                    LRouter.navigatorCtx(context).push(Routes.pPPSearchPage);
                  },
                ),
                ModuleMenuItem(
                  text: "权鸟资讯",
                  image: "img_information.png",
                  callback: () async {
                    LRouter.navigatorCtx(context)
                        .push(Routes.artcleDynamicPage);
                  },
                ),
              ]),
        )),
        PartRefreshWidget(_menuIndicatorGlobalKey, () {
          return Container(
            width: ScreenAdapter.width(50),
            height: ScreenAdapter.height(8),
            alignment: Alignment(_alignmentY, 0),
            decoration: BoxDecoration(
                color: ThemeColors.colorType34,
                borderRadius:
                    BorderRadius.all(Radius.circular(ScreenAdapter.width(10)))),
            child: Container(
              width: ScreenAdapter.width(25),
              height: ScreenAdapter.height(8),
              decoration: BoxDecoration(
                  color: ThemeColors.colorType6,
                  borderRadius: BorderRadius.all(
                      Radius.circular(ScreenAdapter.width(10)))),
            ),
          );
        }),
      ]),
    );
  }

  /// 初始化专区（包含 铁路采购 | 军队采购）
  Widget _initModuleZone() {
    return Container(
      height: ScreenAdapter.height(120),
      margin: EdgeInsets.only(
          left: ScreenAdapter.width(30),
          right: ScreenAdapter.width(30),
          top: ScreenAdapter.height(5)),
      child: Row(
        children: <Widget>[
          Expanded(
              flex: 1,
              child: InkWell(
                child: Image.asset(
                  RPath.imgPath + "img_railway_enter.png",
                  fit: BoxFit.cover,
                ),
                onTap: () {
                  LRouter.navigatorCtx(context).push(Routes.railwayPage);
                },
              )),
          SizedBox(width: ScreenAdapter.width(20)),
          Expanded(
              flex: 1,
              child: InkWell(
                child: Image.asset(RPath.imgPath + "img_army_enter.png",
                    fit: BoxFit.cover),
                onTap: () {
                  LRouter.navigatorCtx(context).push(Routes.armyPage);
                },
              )),
        ],
      ),
    );
  }

  /// 初始化轮播通知公告
  Widget _initNotice() {
    return Container(
        height: ScreenAdapter.height(50),
        margin: EdgeInsets.only(
            left: ScreenAdapter.width(30),
            right: ScreenAdapter.width(30),
            top: ScreenAdapter.height(10)),
        child: IntrinsicHeight(
          child: Row(
            children: <Widget>[
              Container(
                width: ScreenAdapter.width(38),
                height: ScreenAdapter.height(30),
                margin: EdgeInsets.only(right: ScreenAdapter.width(20)),
                child: Image.asset(RPath.imgPath + "icon_blue_notice.png",
                    width: ScreenAdapter.width(38),
                    height: ScreenAdapter.width(38)),
              ),
              Expanded(
                child: IgnorePointer(
                    child: PartRefreshWidget(_noticeGlobalKey, () {
                  return CarouselSlider(
                    options: CarouselOptions(
                      viewportFraction: 1.0,
                      autoPlayInterval: Duration(seconds: 3),
                      autoPlay: true,
                      scrollDirection: Axis.vertical,
                    ),
                    items: _noticeDatas.map((info) {
                      return Builder(
                        builder: (BuildContext context) {
                          return GestureDetector(
                            child: Container(
                                child: RichText(
                                    maxLines: 1,
                                    softWrap: true,
                                    overflow: TextOverflow.ellipsis,
                                    text: TextSpan(
                                      text: "${info.h1} ",
                                      style: TextStyle(
                                          fontSize: ScreenAdapter.sp(25),
                                          color: ThemeColors.colorType3,
                                          fontWeight: FontWeight.bold),
                                      children: <TextSpan>[
                                        TextSpan(
                                          text: "${info.h2} ",
                                          style: TextStyle(
                                              fontSize: ScreenAdapter.sp(26),
                                              color: ThemeColors.colorType1,
                                              fontWeight: FontWeight.w500),
                                        ),
                                        TextSpan(
                                            text: info.h3,
                                            style: TextStyle(
                                                fontSize: ScreenAdapter.sp(26),
                                                color: ThemeColors.colorType10,
                                                fontWeight: FontWeight.w500)),
                                        TextSpan(
                                            text: info.h4,
                                            style: TextStyle(
                                                fontSize: ScreenAdapter.sp(26),
                                                color: ThemeColors.colorType1,
                                                fontWeight: FontWeight.w500)),
                                        TextSpan(
                                            text: info.h5,
                                            style: TextStyle(
                                                fontSize: ScreenAdapter.sp(26),
                                                color: ThemeColors.colorType1,
                                                fontWeight: FontWeight.w500))
                                      ],
                                    ))
                                // TextHighlight(
                                //   content: info != null
                                //       ? (info.h1 +
                                //           info.h2 +
                                //           info.h3 +
                                //           info.h4 +
                                //           info.h5)
                                //       : "-",
                                //   keyWord: info != null ? info.h3 : "",
                                //   maxLines: 1,
                                //   normalStyle: TextStyle(
                                //       color: ThemeColors.colorType1,
                                //       fontSize: ScreenAdapter.sp(26),
                                //       fontWeight: FontWeight.w500),
                                //   highlightStyle: TextStyle(
                                //       color: ThemeColors.colorType10,
                                //       fontSize: ScreenAdapter.sp(26),
                                //       fontWeight: FontWeight.w500),
                                // ),
                                ),
                          );
                        },
                      );
                    }).toList(),
                  );
                })),
              ),
            ],
          ),
        ));
  }

  /// 线条
  Widget _initLine() {
    return Container(
      height: ScreenAdapter.height(10),
      margin: EdgeInsets.only(top: ScreenAdapter.height(15)),
      color: ThemeColors.colorType11,
    );
  }
}

///  热搜关键词Item
class ButtonItem extends StatelessWidget {
  ButtonItem({
    Key key,
    @required this.text,
    this.callback,
  }) : super(key: key);

  final String text;
  final VoidCallback callback;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: Padding(
        padding: EdgeInsets.only(
            top: ScreenAdapter.width(20), bottom: ScreenAdapter.width(20)),
        child: Text(this.text,
            style: TextStyle(
                color: ThemeColors.colorType1,
                fontSize: ScreenAdapter.sp(26),
                fontWeight: FontWeight.w400)),
      ),
      onTap: callback,
    );
  }
}

/// 菜单模块Item
class ModuleMenuItem extends InkWell {
  ModuleMenuItem({
    Key key,
    @required this.text,
    @required this.image,
    @required this.callback,
  }) : super(key: key);

  final String text;

  final String image;

  final GestureTapCallback callback;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: Container(
        width: ScreenAdapter.width(140),
        height: ScreenAdapter.height(140),
        child: Column(
          children: <Widget>[
            Image.asset(RPath.imgPath + image,
                width: ScreenAdapter.width(100),
                height: ScreenAdapter.height(100)),
            SizedBox(height: ScreenAdapter.height(10)),
            Text(text,
                style: TextStyle(
                    color: ThemeColors.colorType1,
                    fontSize: ScreenAdapter.sp(26),
                    fontWeight: FontWeight.w500))
          ],
        ),
      ),
      onTap: callback,
    );
  }
}
